﻿using AutoMapper;
using System;
using System.Linq;
using DomainModels = Ideaa.Domain.Models;
using PersistedModels = Ideaa.Data.Models;
using Ideaa.Core.Extensions;

namespace Ideaa.Data.Mappings
{
    public class DomainToPersistedMappingProfile : Profile
    {
        public override string ProfileName
        {
            get { return "DomainToPersistedMappings"; }
        }

        protected override void Configure()
        {
            Mapper.CreateMap<DomainModels.Base.BaseEntity, PersistedModels.Base.BaseEntity>()
                .Include<DomainModels.Base.PostEntity, PersistedModels.Base.PostEntity>()
                .IgnoreAllVirtual()
                .ForMember(dest => dest.Id, opt => opt.Ignore())
                .ForMember(dest => dest.UserId, opt => opt.MapFrom( src => src.CreatedUserId));

            Mapper.CreateMap<DomainModels.Base.PostEntity, PersistedModels.Base.PostEntity>()
                .Include<DomainModels.Idea.Idea, PersistedModels.Idea>()
                .Include<DomainModels.Idea.Suggestion, PersistedModels.Suggestion>()
                //.InheritMappingFromBaseType()
                .IgnoreAllVirtual();
            
            Mapper.CreateMap<DomainModels.Idea.Idea, PersistedModels.Idea>()
                //.InheritMappingFromBaseType()
                .IgnoreAllVirtual();

            Mapper.CreateMap<DomainModels.Idea.Suggestion, PersistedModels.Suggestion>()
                .IgnoreAllVirtual();
        }
    }
}
